﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Script.Services;
using System.Web.Services;
using System.Data;
using System.Configuration;
using Dgc.Model;
using CyberVN.DBUtility;
using Dgc.Utility;
using System.IO;
using System.Text;
using System.Security.Cryptography;
using Dgc.BLL;
using System.Collections;

namespace JSONP_Service
{
    /// <summary>
    /// Summary description for JSONP_EndPoint
    /// </summary>
   // [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    [ScriptService]
    public class JSONP_EndPoint : System.Web.Services.WebService
    {
        string msql = "";
        



        [WebMethod]

        [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
        public string GetSearchChildrent(int typeId)
        {

            //Type:1(Bai Giang), 2(Luyen Thi)
            string jsonString = "";
            //int total;
            //if (Type == 1) 
            //{ 
            msql = string.Format("select * from [uf_GetListSubjects]({0})", typeId);
            DataTable dt = DBHelper.ExcuteFromCmd(msql, null);
            jsonString = JSONHelper.FromDataTable(dt);
            //}
            //else if (Type == 2)
            //{

            //    DethiCategoryBLL bll_ = new DethiCategoryBLL();
            //    IList<thaytro_DethiCategory> lst_ = bll_.GetList(typeId, false, string.Empty, 1, 20, out total);


            //    DataContractJsonSerializer serializer = new DataContractJsonSerializer(lst_.GetType());
            //    MemoryStream ms = new MemoryStream();
            //    serializer.WriteObject(ms, lst_);
            //    jsonString = Encoding.UTF8.GetString(ms.ToArray());
            //    ms.Close();
            //}

            return jsonString;
        }


        [WebMethod]
        [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
        public string GetListLecture(int IDMon,string SearchName,int UserID)
        {
            //UserID=0 == >Ko kiem tra user
            string jsonString = "";
            string UploadUser = "http://thaytro.vn" + ConfigurationManager.AppSettings["UploadUser"];
            msql = string.Format(" select * from uf_GetListLecture({0},'{1}','{2}',{3})", IDMon, UploadUser, SearchName, UserID);
            DataTable dt = DBHelper.ExcuteFromCmd(msql, null);
            jsonString = JSONHelper.FromDataTable(dt);
            return jsonString;
        }


        [WebMethod]
        [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
        public string GetListVideo(int LectureId, int TypeID)
        {
            //Type:1(Bai Giang), 2(Luyen Thi)
            string jsonString = "";

            msql = string.Format("select * from [uf_GetListVideo]({0},{1})", LectureId, TypeID);
            DataTable dt = DBHelper.ExcuteFromCmd(msql, null);
            jsonString = JSONHelper.FromDataTable(dt);
            return jsonString;
        }

        //private string GetIndentifer(thaytro_LectureCategory obj, thaytro_LectureVideo objVideo)
        //{
        //    string re = string.Empty;
        //    enuTypeLectureCategory enu = (enuTypeLectureCategory)obj.Type;
        //    switch (enu)
        //    {
        //        case enuTypeLectureCategory.PreparTenthGrade:
        //        case enuTypeLectureCategory.TenthGrade:
        //        case enuTypeLectureCategory.EleventhGrade:
        //        case enuTypeLectureCategory.TwelfthGrade:
        //            re = Path.Combine(ConfigurationManager.AppSettings["LectureVideoIdentifierPT"], objVideo.VideoFile);
        //            break;

        //        case enuTypeLectureCategory.PreparUniversity:
        //            re = Path.Combine(ConfigurationManager.AppSettings["LectureVideoIdentifierDH"], objVideo.VideoFile);
        //            break;
        //        case enuTypeLectureCategory.PreparUniversityVIP:
        //            re = Path.Combine(ConfigurationManager.AppSettings["LectureVideoIdentifierDHCT"], objVideo.VideoFile);
        //            break;
        //        default:
        //            re = Path.Combine(ConfigurationManager.AppSettings["LectureVideoIdentifier"], objVideo.VideoFile);
        //            break;

        //    }
        //    return re;
        //}




        [WebMethod]
        [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
        public string GetListLectureSeeMore(int ID)
        {
            //Type:1(Bai Giang), 2(Luyen Thi)
            string jsonString = "";

            //if (Type == 1)
            //{
            //string UploadUser = "http://thaytro.vn" + ConfigurationManager.AppSettings["UploadUser"];
            msql = "select * from uf_GetListLectureSeeMore()";
            DataTable dt = DBHelper.ExcuteFromCmd(msql, null);
            jsonString = JSONHelper.FromDataTable(dt);
            //}
            //else if (Type == 2)
            //{


            //}

            return jsonString;
        }



        [WebMethod]
        [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
        public string GetListLectureNew(int ID)
        {
            
            //Type:1(Bai Giang), 2(Luyen Thi)
            string jsonString = "";

            //if (Type == 1)
            //{
            //string UploadUser = "http://thaytro.vn" + ConfigurationManager.AppSettings["UploadUser"];
            msql = "select * from uf_GetListLectureNew()";
            DataTable dt = DBHelper.ExcuteFromCmd(msql, null);
            jsonString = JSONHelper.FromDataTable(dt);
            //}
            //else if (Type == 2)
            //{


            //}

            return jsonString;
        


            /*
            string jsonString = "";
            msql = "select * from uf_GetListChuyenDe(3) order by [Ordering] desc";
            DataTable dt = DBHelper.ExcuteFromCmd(msql, null);

            jsonString = JSONHelper.FromDataTable(dt);
            return jsonString;
             * 
             * */


        }

        [WebMethod]
        [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
        public string GetListLectureNew1(int ID)
        {
            /*
            //Type:1(Bai Giang), 2(Luyen Thi)
            string jsonString = "";

            //if (Type == 1)
            //{
            //string UploadUser = "http://thaytro.vn" + ConfigurationManager.AppSettings["UploadUser"];
            msql = "select * from uf_GetListLectureNew()";
            DataTable dt = DBHelper.ExcuteFromCmd(msql, null);
            jsonString = JSONHelper.FromDataTable(dt);
            //}
            //else if (Type == 2)
            //{


            //}

            return jsonString;
             * */


            /*
            string jsonString = "";
            msql = "select * from uf_GetListChuyenDe(3) order by [Ordering] desc";
            DataTable dt = DBHelper.ExcuteFromCmd(msql, null);

            jsonString = JSONHelper.FromDataTable(dt);
            return jsonString;
             * 
             * */



            string jsonString = "";
            string jsonString_ChuyenDe = "";
            string jsonString_Lecture = "";

            msql = " select * from uf_GetListLecture(5,'/resource/upload/user')";
            DataTable dt = DBHelper.ExcuteFromCmd(msql, null);

            DataView dv = new DataView(dt);

            //getting distinct values for group column
            DataTable dt_ChuyenDe = dv.ToTable(true, new string[] { "IdChuyenDe", "ChuyenDeName" });
            int ii = 1;
            foreach (DataRow row in dt_ChuyenDe.Rows)
            {



                jsonString_ChuyenDe = JSONHelper.FromDataRow1(row);


                DataRow[] row_Lecture = dt.Select("IdChuyenDe=" + row["IdChuyenDe"]);
                DataTable dt_Lecture = new DataTable();

                dt_Lecture.Columns.Add("Id", typeof(int));
                dt_Lecture.Columns.Add("IdMon", typeof(int));
                dt_Lecture.Columns.Add("IdLop", typeof(int));
                dt_Lecture.Columns.Add("CategoryId", typeof(int));
                dt_Lecture.Columns.Add("Name", typeof(string));
                dt_Lecture.Columns.Add("Description", typeof(string));
                dt_Lecture.Columns.Add("Price", typeof(float));
                dt_Lecture.Columns.Add("Published", typeof(string));
                dt_Lecture.Columns.Add("Ordering", typeof(int));
                dt_Lecture.Columns.Add("Images", typeof(string));
                dt_Lecture.Columns.Add("Path", typeof(string));
                dt_Lecture.Columns.Add("Tag", typeof(string));
                dt_Lecture.Columns.Add("IdTeacher", typeof(int));
                dt_Lecture.Columns.Add("TeacherName", typeof(string));
                dt_Lecture.Columns.Add("IdChuyenDe", typeof(int));
                dt_Lecture.Columns.Add("ChuyenDeName", typeof(string));
                dt_Lecture.Columns.Add("IDChuong", typeof(int));
                dt_Lecture.Columns.Add("ChuongName", typeof(string));
                dt_Lecture.Columns.Add("TeacherImage", typeof(string));
                dt_Lecture.Columns.Add("IDthaytro_Teacher", typeof(int));

                for (int i = 0; i < row_Lecture.Length; i++)
                {
                    dt_Lecture.Rows.Add(
                            row_Lecture[i]["Id"],
                            row_Lecture[i]["IdMon"],
                            row_Lecture[i]["IdLop"],
                            row_Lecture[i]["CategoryId"],
                            row_Lecture[i]["Name"],
                            row_Lecture[i]["Description"],
                            row_Lecture[i]["Price"],
                            row_Lecture[i]["Published"],
                            row_Lecture[i]["Ordering"],
                            row_Lecture[i]["Images"],
                            row_Lecture[i]["Path"],
                            row_Lecture[i]["Tag"],
                            row_Lecture[i]["IdTeacher"],
                            row_Lecture[i]["TeacherName"],
                            row_Lecture[i]["IdChuyenDe"],
                            row_Lecture[i]["ChuyenDeName"],
                            row_Lecture[i]["IDChuong"],
                            row_Lecture[i]["ChuongName"],
                            row_Lecture[i]["TeacherImage"],
                            row_Lecture[i]["IDthaytro_Teacher"]
                        );
                }



                jsonString_Lecture = JSONHelper.FromDataTable1(dt_Lecture, "OBJECT_Lecture");


                if (ii == dt_ChuyenDe.Rows.Count)
                {
                    jsonString = jsonString + "{" + jsonString_ChuyenDe + "," + jsonString_Lecture + "}";
                }
                else
                {
                    jsonString = jsonString + "{" + jsonString_ChuyenDe + "," + jsonString_Lecture + "},";
                }
                ii++;











                /*
                DataRow[] row_Chuong = dt.Select("IdChuyenDe=" + row["IDChuyenDe"]);
                DataTable dt_Chuong = new DataTable();
                dt_Chuong.Columns.Add("IDChuong", typeof(int));
                dt_Chuong.Columns.Add("ChuongName", typeof(string));
                for (int i = 0; i < row_Chuong.Length; i++)
                {
                    dt_Chuong.Rows.Add(row_Chuong[i]["IdChuong"], row_Chuong[i]["ChuongName"]);
                }
                DataView dv_Chuong = new DataView(dt_Chuong);
                //getting distinct values for group column
                DataTable dt_Chuong_ = dv_Chuong.ToTable(true, new string[] { "IdChuong", "ChuongName" });
                jsonString_Chuong = JSONHelper.FromDataTable1(dt_Chuong_, "Object_Chuong");


                if (ii == dt_ChuyenDe.Rows.Count)
                {
                    jsonString = jsonString + "{" + jsonString_ChuyenDe + "," + jsonString_Chuong + "}";
                }
                else
                {
                    jsonString = jsonString + "{" + jsonString_ChuyenDe + "," + jsonString_Chuong + "},";
                }
                ii++;
                 * 
                 * */



            }





            jsonString = "{\"OBJECT\":[" + jsonString + "]}";
            return jsonString;
        }

        public DataTable GroupBy(string i_sGroupByColumn, string i_sGroupByColumnName, DataTable i_dSourceTable)
        {

            DataView dv = new DataView(i_dSourceTable);

            //getting distinct values for group column
            DataTable dtGroup = dv.ToTable(true, new string[] { "IdChuyenDe", "ChuyenDeName" });


            //returning grouped/counted result
            return dtGroup;
        }




        [WebMethod]
        [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
        public string RegisterUser(string FullName, int Sex, DateTime Birthday, string Address, string Email, string UserName, string Password, DateTime Postdate)
        {
            /*
              @FullName NVarChar(200)=null,
              @Sex TinyInt=null,
              @Birthday datetime =null,
              @Address NVarChar(200)=null,
              @Email NVarChar(200),
              @UserName NVarChar(200),
              @Password NVarChar(200),
             */
            string jsonString = "";
            try
            {
                msql = string.Format("select COUNT(*) from [thaytro_User] where Email='{0}'", Email);
                DataTable dt = DBHelper.ExcuteFromCmd(msql, null);
                if (DBConvert.ParseInt(dt.Rows[0][0]) == 0)
                {
                    Password = StrEnCode(Password);
                    CyberParameter[] param1 = new CyberParameter[9];
                    param1[0] = new CyberParameter("@FullName", System.Data.DbType.String, FullName);
                    param1[1] = new CyberParameter("@Sex", System.Data.DbType.Int32, Sex);
                    param1[2] = new CyberParameter("@Birthday", System.Data.DbType.DateTime, Birthday);
                    param1[3] = new CyberParameter("@Address", System.Data.DbType.String, Address);
                    param1[4] = new CyberParameter("@Email", System.Data.DbType.String, Email);
                    param1[5] = new CyberParameter("@UserName", System.Data.DbType.String, UserName);
                    param1[6] = new CyberParameter("@Password", System.Data.DbType.String, Password);
                    param1[7] = new CyberParameter("@Postdate", System.Data.DbType.DateTime, Postdate);
                    param1[8] = new CyberParameter("@Role", System.Data.DbType.Int32, 4);
                    DBHelper.ExcuteFromStoreNonQuery("sp_RegisterUser", param1);
                    jsonString = "1";//"Xin chúc mừng, bạn đã đăng ký tài khoản thành công.";
                }
                else
                {
                    jsonString = "2";//"Email đã tồn tại, vui lòng sử dụng email khác.";
                }
            }
            catch (Exception)
            {
                jsonString = "0"; //Error
            }
           
            return jsonString;
        }

        [WebMethod]
        [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
        public string UserLogin( string UserName_Email, string Password)
        {
            //  select * from [uf_GetUserLogin]('info@dgc.vn','Dm/Cs7+fy6Ym6OVC/LwObFNNnZX+0qxVZvCFid84rXM=')
            /*
              @UserName NVarChar(200),
              @Password NVarChar(200),
             */
            /*
            string jsonString = "";
            string PasswordEncode = StrEnCode(Password);
            string ImageUser = "http://thaytro.vn/resource/upload/user/";
            msql = string.Format("select '{2}' as PasswordNoEncode,'{3}'+Image as ImageUser, * from [thaytro_User] where (UserName='{0}' or Email='{0}')and Password='{1}'", UserName_Email, PasswordEncode, Password, ImageUser);
            DataTable dt = DBHelper.ExcuteFromCmd(msql, null);

            jsonString = JSONHelper.FromDataTable(dt);
            return jsonString;

            */
            string jsonString = "";

            string PasswordEncode = StrEnCode(Password);
            msql = string.Format("select * from [uf_GetUserLogin]('{0}','{1}','{2}')", UserName_Email, PasswordEncode, Password);
            DataTable dt = DBHelper.ExcuteFromCmd(msql, null);
            jsonString = JSONHelper.FromDataTable(dt);
          
            return jsonString;



        }
        public static string StrEnCode(string str)
        {
            UnicodeEncoding encoder = new UnicodeEncoding();
            SHA256Managed sha256hasher = new SHA256Managed();
            byte[] hashedDataBytes = sha256hasher.ComputeHash(encoder.GetBytes(str));
            return Convert.ToBase64String(hashedDataBytes);
        }



        [WebMethod]
        [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
        public string UpdateUser(int id,string FullName, int Sex, DateTime Birthday, string Address, string Password)
        {
            /*
              @FullName NVarChar(200)=null,
              @Sex TinyInt=null,
              @Birthday datetime =null,
              @Address NVarChar(200)=null,
              @Email NVarChar(200),
              @UserName NVarChar(200),
              @Password NVarChar(200),
             */
            string jsonString = "";
            try
            {
                CyberParameter[] param1 = new CyberParameter[6];
                param1[0] = new CyberParameter("@Id", System.Data.DbType.Int32, id);
                param1[1] = new CyberParameter("@FullName", System.Data.DbType.String, FullName);
                param1[2] = new CyberParameter("@Sex", System.Data.DbType.Int32, Sex);
                param1[3] = new CyberParameter("@Birthday", System.Data.DbType.DateTime, Birthday);
                param1[4] = new CyberParameter("@Address", System.Data.DbType.String, Address);
                param1[5] = new CyberParameter("@Password", System.Data.DbType.String, Password);
                DBHelper.ExcuteFromStoreNonQuery("sp_UpdateUser", param1);
                jsonString = "1";//"Xin chúc mừng, bạn đã đăng ký tài khoản thành công.";
            }
            catch (Exception)
            {
                jsonString = "0"; //Error
            }

            return jsonString;
        }


        [WebMethod]
        [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
        public string UserLectureBuy(int UserId, int LectureId, float Price)
        {
            string jsonString = "";
            try
            {
                msql = string.Format("select ISNULL(SUM(cr_value_card),0) from dbo.thaytro_db_card where cr_id_mem_card={0}", UserId);
                DataTable dt = DBHelper.ExcuteFromCmd(msql, null);
                if (DBConvert.ParseInt(dt.Rows[0][0]) > Price)
                {
                    CyberParameter[] param1 = new CyberParameter[3];
                    param1[0] = new CyberParameter("@UserId", System.Data.DbType.Int32, UserId);
                    param1[1] = new CyberParameter("@LectureId", System.Data.DbType.Int32, LectureId);
                    param1[2] = new CyberParameter("@Price", System.Data.DbType.Int32, Price);
                    DBHelper.ExcuteFromStoreNonQuery("sp_UserLectureBuy", param1);
                    jsonString = "1";//" thành công.";
                }
                else
                {
                    jsonString = "2";//" không đủ tiền";
                }
                
            }
            catch (Exception)
            {
                jsonString = "0";//Error
            }

            return jsonString;
        }

        [WebMethod]
        [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
        public string UserServiceBuy(int UserId, int ServiceId, float Price)
        {
            string jsonString = "";
            try
            {
                msql = string.Format("select ISNULL(SUM(cr_value_card),0) from dbo.thaytro_db_card where cr_id_mem_card={0}", UserId);
                DataTable dt = DBHelper.ExcuteFromCmd(msql, null);
                if (DBConvert.ParseInt(dt.Rows[0][0]) > Price)
                {
                    CyberParameter[] param1 = new CyberParameter[3];
                    param1[0] = new CyberParameter("@UserId", System.Data.DbType.Int32, UserId);
                    param1[1] = new CyberParameter("@ServiceId", System.Data.DbType.Int32, ServiceId);
                    param1[2] = new CyberParameter("@Price", System.Data.DbType.Int32, Price);
                    DBHelper.ExcuteFromStoreNonQuery("sp_UserServiceBuy", param1);
                    jsonString = "1";//" thành công.";
                }
                else
                {
                    jsonString = "2";//" không đủ tiền";
                }

                
            }
            catch (Exception)
            {
                jsonString = "0"; //Error
            }

            return jsonString;
        }



        [WebMethod]
        [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
        public string CheckLectureUser(int userid, int lectureId)
        {
            string jsonString = "";
            try
            {
                CyberParameter[] param1 = new CyberParameter[2];
                param1[0] = new CyberParameter("@user", System.Data.DbType.Int32, userid);
                param1[1] = new CyberParameter("@lectureId", System.Data.DbType.Int32, lectureId);
                object ob = DBHelper.ExcuteScalarFromStore("sp_CheckLectureUser", param1);
                jsonString = Convert.ToInt32(ob) > 0 ? "1" : "0";
                // 1:mua,0:chua mua
            }
            catch (Exception)
            {
                jsonString = "0"; //Error
            }

            return jsonString;
        }

        [WebMethod]
        [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
        public string CheckLectureUserDownload(int userid, int lectureId)
        {
            string jsonString = "";
            try
            {
                CyberParameter[] param1 = new CyberParameter[2];
                param1[0] = new CyberParameter("@user", System.Data.DbType.Int32, userid);
                param1[1] = new CyberParameter("@lectureId", System.Data.DbType.Int32, lectureId);
                object ob = DBHelper.ExcuteScalarFromStore("sp_CheckLectureUserDownload", param1);
                jsonString = Convert.ToInt32(ob).ToString();
                /*
                1:chua mua,chua kich hoat
                2:da mua,da kich hoat
                3:da mua,chua kich hoat
                4:chua mua,da kich hoat
                */

            }
            catch (Exception)
            {
                jsonString = "0"; //Error
            }

            return jsonString;
        }


        [WebMethod]
        [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
        public string AddCard(string CardCode, string SerialCode, string Supplier,int UserId)
        {
            APICardCharging cardCharging = null ;
            string ss = string.Empty;
            string jsonString = "";
            try
            {
                ss = cardCharging.login();
                if (!string.IsNullOrEmpty(ss))
                {
                    string carddata = string.Empty;
                    //switch (drpProvider.SelectedValue)
                    //{
                    //    case "VNP":
                    //    case "VMS":
                    //        carddata = txtNumber.Text.Trim() + ":" + drpProvider.SelectedValue;
                    //        break;
                    //    default:
                    carddata = SerialCode + ":" + CardCode + "::" + Supplier;
                    //        break;
                    //}

                    jsonString = cardCharging.cardCharging(ss, carddata, "UserName", UserId);
                    System.Threading.Thread.Sleep(500);
                }
            }
            catch (Exception)
            {
                jsonString = "Nạp tiền không thành công,vui lòng liên hệ thaytro.vn"; //Error
            }
            finally
            {
                if (!string.IsNullOrEmpty(ss))
                    cardCharging.logout(ss);
            }
            return jsonString;
        }



        [WebMethod]
        [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
        public string GetlinkExam(int cid)
        {
         
            int tglb;
            string filenameExam;
            string filenameGuideExam ="";
            string maDethi;
            bool isPdfExam;
            bool isPdfGuideExam;
            string swfFile="";
            string dirUploadMedia = Utils.CombineUrl("http://thaytro.vn", ConfigurationManager.AppSettings["UploadDethiMedia"]);
            string jsonString = "";
            Generic<thaytro_Dethi_noidung> bll = new Generic<thaytro_Dethi_noidung>();

            thaytro_Dethi_noidung obj = new thaytro_Dethi_noidung() { Id = cid };
            obj = bll.Load(obj, new string[] { "Id" });


            if (obj != null)
            {
                maDethi = obj.Ma_de_thi;
                filenameExam = obj.File_de_thi;
                tglb = obj.Time_de_thi;
                if (obj.Loai_de_thi == (int)enuExamType.tracnghiem)
                {

                }
                else
                {
                    filenameGuideExam = obj.Hd_de_thi;
                }

                isPdfExam = Path.GetExtension(filenameExam) == ".swf" ? true : false;
                isPdfGuideExam = Path.GetExtension(filenameGuideExam) == ".swf" ? true : false;
                if (!string.IsNullOrEmpty(filenameExam))
                {
                    try
                    {
                        if (isPdfExam)
                        {
                            
                            string tempPath = ConfigurationManager.AppSettings["UploadDethi"]+"/"+ filenameExam;
                            string fullPath = "http://thaytro.vn"+tempPath;
                            int i = fullPath.IndexOf(".swf");
                            string chuoi = fullPath.Substring(0, i);
                            swfFile = chuoi + ".pdf";
                        }
                        else
                        {
                            string dirUpload = Path.Combine(ConfigurationManager.AppSettings["UploadDethi"]);
                            string fullpath="http://thaytro.vn"+dirUpload +"/"+ maDethi;
                            swfFile = fullpath + "/" + filenameExam;
                        }
                    }
                    catch { }
                }
                

                

                jsonString = swfFile;
                
            }
            return jsonString;
        }






        [WebMethod]
        [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
        public string GetListExam(int dm_de_thi)
        {
            string jsonString = "";
            msql = string.Format(" select * from uf_GetListExam({0})", dm_de_thi);
            DataTable dt = DBHelper.ExcuteFromCmd(msql, null);
            jsonString = JSONHelper.FromDataTable(dt);
            return jsonString;
        }


        [WebMethod]
        [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
        public string GetExamDetail(int IDDeThi)
        {
            string jsonString = "";
            msql = string.Format(" select * from uf_GetExamDetail({0})", IDDeThi);
            DataTable dt = DBHelper.ExcuteFromCmd(msql, null);
            jsonString = JSONHelper.FromDataTable(dt);
            return jsonString;
        }



        [WebMethod]
        [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
        public string GetListLectureComment(int LectureID)
        {
            string jsonString = "";
            msql = string.Format(" select Email,LectureID,UserID,Comment from uf_GetListLectureComment({0})", LectureID);
            DataTable dt = DBHelper.ExcuteFromCmd(msql, null);
            jsonString = JSONHelper.FromDataTable(dt);
            return jsonString;
        }



    }
}
